home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 813 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP! File Pointers
  5. Date: 9 Jan 1996 07:37 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <9JAN199607374098@erich.triumf.ca>
  9. References: <4csr4c$fem@newsbf02.news.aol.com>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4csr4c$fem@newsbf02.news.aol.com>, roberino@aol.com (Roberino) writes...
  14. >I am currently trying to keep one file open while opening other
  15. >files one at a time using a separate file pointer.  However, as
  16. >soon as I read a line from the second file, the first file pointer
  17. >somehow gets destroyed and set to some position in the newly
  18. >opened file.  Has anyone else encountered this?  And if so,
  19. >is there a solution? (i.e. A way to protect the first file pointer
  20. >from being overwritten.)
  21. >Here are the steps I am performing:
  22. >void main()
  23.  
  24. According to the ANSI/ISO C standard, main() _must_ return an int (despite many
  25. books to the contrary).  Then you need a "return 0;" at the end of main().
  26. (However, void main() rarely causes any problems...)
  27.  
  28. >{
  29. >    FILE *File1;
  30. >    FILE *File2;
  31. >    File1 =   fopen("FILENAME", "r+");
  32. >    
  33. >    /* loop through lines in File1 using fgets() */
  34. >    if (Condition) /* just indicating some condition was met */
  35. >    {
  36. >        File2 = fopen("FILENAME2", "r+");
  37. >      
  38. >        fgets(Line, File2); <----- As soon as this occurs, File1 gets
  39. >                                          wiped out.  Why?
  40.  
  41. In my books, fgets() takes 3 parameters: buffer, size, stream - so this should
  42. be perhaps fgets(Line, sizeof(LINE), File2);
  43.  
  44. How is Line declared?  It should be declared as a char array large enough to
  45. hold the input line.
  46.  
  47. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  48. Internet: bennett@triumf.ca         | of one another only when one can be
  49. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  50. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  51. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.